package com.songshuai.pangu.api.controller;

import com.songshuai.pangu.api.service.SalesClientService;
import com.songshuai.webapi.baseapi.dto.pangu.request.salesclient.CustomerListReqDto;
import com.songshuai.webapi.baseapi.dto.pangu.response.salesclient.CustomerInfoDto;
import com.songshuai.webapi.baseapi.dto.pangu.response.salesclient.LabelDto;
import com.songshuai.webapi.baseapi.enumerations.ResultStatus;
import com.songshuai.webapi.baseapi.pojo.BaseParmDto;
import com.songshuai.webapi.baseapi.pojo.QueryResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

@Slf4j
@Api("盘古销售端接口")
@RestController
@RequestMapping("/api/pangu/salesClient/")
public class SalesClientController {


    @Autowired
    private SalesClientService salesClientService;
    /**
     *
     * @param searchStr 搜索字符串（支持客户姓名，手机，标签模糊搜索）
     * @userId 销售用户ID
     * @return
     */
    @ApiOperation(value = "获取销售客户列表")
    @RequestMapping(value = "getCustomerList", method = RequestMethod.POST)
    public CompletableFuture<QueryResponse<List<CustomerInfoDto>>> getCustomerList(@RequestBody BaseParmDto<CustomerListReqDto> request){

        return CompletableFuture.supplyAsync(()->{

            try {
                return salesClientService.getCustomerList(request);
            }catch (Exception e){
                log.error("api/pangu/salesClient/getCustomerList", e);
                return new QueryResponse(ResultStatus.FAILOfficial);
            }

//            List<CustomerInfoDto> lists = new ArrayList<CustomerInfoDto>();
//            CustomerInfoDto customerInfo = null;
//            for(int i=1; i<5; i++ ) {
//                customerInfo  = new CustomerInfoDto();
//                customerInfo.setCustomerId(String.valueOf(i));
//                customerInfo.setCustomerName("测试客户"+i);
//                customerInfo.setLabels(this.getLabelDtos());
//                customerInfo.setIsBinding("1");
//                lists.add(customerInfo);
//            }
//            return QueryResponse.setResData(lists);
        });
    }

    /*测试标签*/
    private List<LabelDto> getLabelDtos(){

        List<LabelDto> lists = new ArrayList<LabelDto>();
        LabelDto labelDto = null;
        for(int i=1; i<2; i++ ) {
            labelDto = new LabelDto();
            labelDto.setLabelId(String.valueOf(i));
            labelDto.setLabelName("测试标签"+i);
            lists.add(labelDto);
        }
        return lists;
    }














}
